package org.zfm.util.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public enum RedisPoolUtil {
    INSTANCE;
    private final static JedisPool POOL;
    static {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(2);//空闲时最大连接数
        config.setMaxTotal(10);//最大连接数
        config.setMaxWaitMillis(2000);
        config.setTestOnBorrow(true);
        POOL = new JedisPool(config,"127.0.0.1",6379,2000,"0717");
    }

    /**
     * 从连接池中获取连接
     * @return
     */
    public Jedis getJedis(){
        return POOL.getResource();
    }

    /**
     * 将指定连接放回连接池
     * @param jedis
     */
    public void close(Jedis jedis){
        jedis.close();
    }


}
